package com.eastfair.common.controller;

import com.eastfair.common.dto.*;
import com.eastfair.common.service.CrmCustomerInfoSyncService;
import com.eastfair.common.service.CrmHostSyncService;
import com.eastfair.common.service.CrmPrjInfSyncService;
import com.eastfair.common.service.CrmSvcInfSyncService;
import com.eastfair.core.base.R;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * <p>
 * 前端控制器
 * 
 * </p>
 *
 * @author clm
 * @date 2022-12-22
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/toCrm")
@Api(value = "toCrm", tags = "")
public class ToCRMController{

    @Resource
    private CrmCustomerInfoSyncService crmCustomerInfoSyncService;

    @Resource
    private CrmPrjInfSyncService crmPrjInfSyncService;

    @Resource
    private CrmSvcInfSyncService crmSvcInfSyncService;

    @Resource
    private CrmHostSyncService crmHostSyncService;

    @PostMapping("/syncObjectInfo")
    public R<Boolean> syncObjectInfo(@RequestBody GmApiPrjInfDtos gmApiPrjInfDtos) {
        crmPrjInfSyncService.syncPrjInf(gmApiPrjInfDtos);
        return R.success(true);
    }

    @PostMapping("/syncCustomerObjectSponsor")
    public R<Boolean> syncCustomerObjectSponsor(@RequestBody GmApiPrjAndHostRelDtos gmApiPrjAndHostRelDtos) {
        crmPrjInfSyncService.syncPrjAndHostRel(gmApiPrjAndHostRelDtos);
        return R.success(true);
    }

    @PostMapping("/syncCustomerServiceProvider")
    public R<Boolean> syncCustomerServiceProvider(@RequestBody GmApiPrjAndSvcRelDtos gmApiPrjAndSvcRelDtos) {
        crmPrjInfSyncService.syncPrjAndSvcRel(gmApiPrjAndSvcRelDtos);
        return R.success(true);
    }

    @PostMapping("/syncCustomerInfo")
    public R<Boolean> syncCustomerInfo(@RequestBody GmApiCstNmInfDtos gmApiCstNmInfDtos) {
        crmCustomerInfoSyncService.syncCustomerInfo(gmApiCstNmInfDtos);
        return R.successDef(true);
    }

    @PostMapping("/syncCustomerAddressInfo")
    public R<Boolean> syncCustomerAddressInfo(@RequestBody GmApiCstAdrInfDtos gmApiCstAdrInfDtos) {
        crmCustomerInfoSyncService.syncCustomerAddressInfo(gmApiCstAdrInfDtos);
        return R.successDef(true);
    }

    @PostMapping("/syncCustomerInvoiceInfo")
    public R<Boolean> syncCustomerInvoiceInfo(@RequestBody GmApiCstIssubillInfDtos gmApiCstIssubillInfDtos) {
        crmCustomerInfoSyncService.syncCustomerInvoiceInfo(gmApiCstIssubillInfDtos);
        return R.successDef(true);
    }

    @PostMapping("/syncCustomerContractInfo")
    public R<Boolean> syncCustomerContractInfo(@RequestBody GmApiCstCtcInfDtos gmApiCstCtcInfDtos) {
        crmCustomerInfoSyncService.syncCustomerContractInfo(gmApiCstCtcInfDtos);
        return R.successDef(true);
    }


    /**
     * 同步服务商
     * @param gmApiSvcInfPageDtos
     * @return
     */
    @PostMapping("/syncServiceProvider")
    public R<Boolean> syncServiceProvider(@RequestBody GmApiSvcInfPageDtos gmApiSvcInfPageDtos) {
        crmSvcInfSyncService.syncSvcInfo(gmApiSvcInfPageDtos);
        return R.success(true);
    }
}

